﻿
namespace LS.Nc6.Application.Cms
{
    public class CmsBannerService : BaseService<CmsBannerEntity>, ICmsBannerService, ITransient
    {
        public async Task<Tuple<List<dynamic>, int, int>> PageDynamicLeftJoinList(Expression<Func<CmsBannerEntity, SysDictionaryEntity, bool>> expression, int page, int limit,
            Expression<Func<CmsBannerEntity, SysDictionaryEntity, object>> expressionOrder, Expression<Func<CmsBannerEntity, SysDictionaryEntity, dynamic>> expressionSelect)
        {
            RefAsync<int> totalCount = 0;

            var items = await DbContext.Instance.Queryable<CmsBannerEntity>().LeftJoin<SysDictionaryEntity>((a, b) => a.BType == b.Dvalue && b.ParentId == SqlFunc.Subqueryable<SysDictionaryEntity>().Where(s => s.Dictype == SysDictionaryType.ENUM_BANNERTYPE.ToString()).Select(s => s.Id))
                .Where(expression).OrderByDescending(expressionOrder).Select(expressionSelect).ToPageListAsync(page, limit, totalCount);
            var totalPages = (int)Math.Ceiling(totalCount / (double)limit);
            return new Tuple<List<dynamic>, int, int>(
                 items, (int)totalCount, totalPages
            );
        }
    }
}
